
*** File created 15th March 2021 


***** Variables used in analysis (unless mentioned, all data are found in subjects. dta file)

* session_num = Unique session ID number (1 - 48)
* Treatment_new = Treatment ID number (1 = Single Round & No Joint Bidding, 2 = Iterative & No Joint Bidding, 3 = Single Round & Joint Bidding 2.5 , 4 = Iterative & Joint Bidding 2.5)
* Treatment_new = Treatment ID number (5 = Single Round & Joint Bidding 1.5, 6 = Iterative & Joint Bidding 1.5, 7 = Single Round & Joint Bidding 1.5, No Indiv Bonus, 8 = Iterative & & Joint Bidding 1.5, No Indiv Bonus)
* Period = Chronological order of period in each treatment (1 - 9)
* Subject = Subject ID number (1 - 8) 
* Profit = period profit (value of winning offer - cost + total bonus received)
* TotalProfit = Cumulative profit, including the present period

* Cost = Cost of item
* Quality = Quality of item
* Edge_Benefit_Left/Edge_Bonus_Left = Bonus associated with Left Neighbor
* Edge_Benefit_Right/Edge_Bonus_Right = Bonus associated with Right Neighbor
* Winner = Identifies whether subject won or not through individual or joint bid.  
* Indiv_Winning = Variable recording if winning offer is an individual offer(=1). A value of 0 can signify that subject was not selected or joint offer was selected.
* Joint_Right_Winning = 1 if Subject's joint offer with their Right neighbor was selected, 0 if not.
* Joint_Left_Winning = 1 if Subject's joint offer with their left neighbor was selected, 0 if not.

* Offer = Final round Individual Offer in a Period (Used for final winner analysis)
* Offer_Left_Own = Subject's own share of joint offer with Left Neighbor
* Offer_Right_Own = Subject's own share of joint offer with Right Neighbor

* Winning_Neighbors = Number of selected neighbors of the subject (does not tell you whether individual or joint bids were selected) 
* FinalRound = Reports round in which stopping rule was satisfied or period ended (<=6)

* Right_Bonus_Earned = 1 if Right neighbor selected and own individual bid selected 
* Right_Bonus_Earned = 1 if Right neighbor selected and own joint bid with left neighbor selected
* Left_Bonus_Earned = 1 if Left neighbor selected and own individual bid selected 
* Left_Bonus_Earned = 1 if Left neighbor selected and own joint bid with right neighbor selected

* Joint_Left = Variable recording if subject expressed interest to submit a joint offer with Left neighbor
* Joint_Right = Variable recording if subject expressed interest to submit a joint offer with Right neighbor

* joint = Variable recording whether a bid is a joint bid or not in the contracts and confirmed data files. 
* This variable is used for analysis presented in Rows 2 and 3 of Table 6. 

* Offer_Subject_Right = Value of offer of subjects whose joint bid with LEFT neighbor is confirmed (confirmed.dta file)
* Offer_Subject_Left = Value of offer of subjects whose joint bid with RIGHT neighbor is confirmed (confirmed.dta file)
* Joint_Subject_Left = Variable that records the ID of the subject for whom the joint bid was confirmed with RIGHT neighbor (confirmed.dta file)
* Joint_Subject_Right = Variable that records the ID of the subject for whom the joint bid was confirmed with LEFT neighbor (confirmed.dta file)
* Cost_Subject_Right = Value of cost of subjects whose joint bid with LEFT neighbor is confirmed (confirmed.dta file)
* Cost_Subject_Left = Value of cost of subjects whose joint bid with RIGHT neighbor is confirmed (confirmed.dta file)
* 

********************** Begin Analysis *********************

************************************************************
*** call datafile to analyze ***
***********************************************************

clear
set more off
cd [[set folder]]
use "subjects.dta", clear

** Unique subject identifier 
** Already defined in subjects.dta
gen subjID = session_num*10+Subject

** Labeling the treatments
label define condition 1 "Single-Individual" 2 "Multi-Individual" 3 "Single-Joint" 4 "Multi-Joint" 5 "Single-Joint1.5" 6 "Multi-Joint1.5" 7 "Single-Joint0" 8 "Multi-Joint0"
label values Treatment_new condition

** Dummy variable for Single Round treatment
gen SingleTreatment = 1 if Treatment_new == 1 | Treatment_new == 3 | Treatment_new == 5 | Treatment_new == 7
replace SingleTreatment = 0 if SingleTreatment != 1

** Dummy variable for Joint Bidding treatment
gen JointTreatment = 1 if Treatment_new == 3 | Treatment_new == 4 | Treatment_new == 5 |Treatment_new == 6 | Treatment_new == 7 | Treatment_new == 8
replace JointTreatment = 0 if JointTreatment != 1

** Dummy variable for No Individual Bonus treatment
gen NoIndivBonus = 1 if Treatment_new>6
replace NoIndivBonus = 0 if Treatment_new<7

** Dummy variables for Cost Benefit Parameter assignment across 9 Auction periods
*** This information is related to information presented in Table 2

** Several Small 
gen Endow1 = 0
replace Endow1 = 1 if param_order == 1 & (Period == 1| Period == 4| Period == 7) 
replace Endow1 = 1 if param_order == 2 & (Period == 3| Period == 6| Period == 9)
replace Endow1 = 1 if param_order == 3 & (Period == 3| Period == 6| Period == 9)

** Single Large
gen Endow2 = 0
replace Endow2 = 1 if param_order == 1 & (Period == 2| Period == 5| Period == 8)
replace Endow2 = 1 if param_order == 2 & (Period == 1| Period == 4| Period == 7)
replace Endow2 = 1 if param_order == 3 & (Period == 2| Period == 5| Period == 8)
  
** Core-Fragment  
gen Endow3 = 0
replace Endow3 = 1 if param_order == 1 & (Period == 3| Period == 6| Period == 9)
replace Endow3 = 1 if param_order == 2 & (Period == 2| Period == 5| Period == 8)
replace Endow3 = 1 if param_order == 3 & (Period == 1| Period == 4| Period == 7)

label define structure 1 "Single-Round" 0 "Multi-Round"
label values SingleTreatment structure

label define bidding 1 "Joint-Individual" 0 "Individual"
label values JointTreatment bidding

** Dummy variable for Super Bonus variation treatment with sessions with superbonus = 2.5 the reference category 
gen SuperBonus = 0 if Treatment_new == 3| Treatment_new == 4
replace SuperBonus = 1 if Treatment_new >= 5

** Dummy variable for Joint bidding treatments with difference by magnitude of joint and individual bonuses
** No Joint Bidding
gen JointTreatmentAug = 0 if JointTreatment == 0
** Joint Bidding with multiplier = 2.5
replace JointTreatmentAug = 1 if Treatment_new == 3| Treatment_new == 4
** Joint Bidding with multiplier = 1.5
replace JointTreatmentAug = 2 if Treatment_new == 5| Treatment_new == 6
** Joint Bidding with multiplier = 1.5 and no Individual bonus
replace JointTreatmentAug = 3 if Treatment_new == 7| Treatment_new == 8

label define augmented 0 "Individual" 1 "Joint-2.5" 2 "Joint-1.5" 3 "Joint-1.5-I0"
label values JointTreatmentAug augmented

** Creating interaction terms between Joint Treatment and Single Round Treatment variable
gen Interactions = JointTreatmentAug*SingleTreatment
tab Interaction, gen(JointSingleInt)

gen costsq = Cost*Cost

** Generating dummy variable for Risk variable
gen RiskAverse = 0 if RiskChoice>3
replace RiskAverse = 1 if RiskChoice <4



**** Auction Performance Metrics

*** Calculating Environmental Benefit OR Quality associated with winning offers for every subject for all possible winning scenarios. 
*** Since subjects are arranged on a circle, we only consider benefit premiums added for the left neighbor or in the clockwise direction
*** so that when the values are summed at the session level for all winners, there is no double counting of benefit premiums. 

** Subject's individual bid is accepted and left neighbor is accepted but right neighbor not accepted
gen IndividualTotalBenefit = (Quality + Edge_Benefit_Left)*Winner if Indiv_Winning == 1 & Left_Bonus_Earned == 1 
** Subject's joint bid is accepted with left neighbor but right neighbor not accepted
replace IndividualTotalBenefit = (Quality + Edge_Benefit_Left)*Winner if Joint_Left_Winning == 1 
** Accounting for quality of subject whose joint bid selected with right neighbor. No bonus included as it is included for right neighbor's value
replace IndividualTotalBenefit = Quality*Winner if Joint_Right_Winning == 1 
** Subject's joint bid with right neighbor is accepted and their left neighbor's individual bid is accepted
replace IndividualTotalBenefit = (Quality + Edge_Benefit_Left)*Winner if Joint_Right_Winning == 1 & Left_Bonus_Earned == 1 
** Accounting for quality of subject whose individual bid selected with right neighbor who is also a winner. No bonus included as it is included for right neighbor's value
replace IndividualTotalBenefit = Quality*Winner if Indiv_Winning == 1 & Right_Bonus_Earned == 1 & Winning_Neighbors == 1
** Isolated project selected
replace IndividualTotalBenefit = Quality*Winner if Indiv_Winning == 1 & Winning_Neighbors == 0
** Did not win
replace IndividualTotalBenefit = 0 if Winner == 0

** Total Environmental Benefit realized during the auction (includes quality premium/bonus) - variable used for session level analysis
bysort session_num Period: egen SessionQuality = total(IndividualTotalBenefit)

** Expense of associated with procuring winning offers 
gen SubjectPayment = (Cost + Profit)*Winner
bysort session_num Period: egen SessionPayment = total(SubjectPayment)

** Calculating number of winning neighbors from individual and joint bids for winners
gen neighbors = Winning_Neighbors if Indiv_Winning == 1
replace neighbors = 1 if Joint_Left_Winning == 1 & Right_Bonus_Earned == 0
replace neighbors = 2 if Joint_Left_Winning == 1 & Right_Bonus_Earned == 1
replace neighbors = 1 if Joint_Right_Winning == 1 & Left_Bonus_Earned == 0
replace neighbors = 2 if Joint_Right_Winning == 1 & Left_Bonus_Earned == 1
replace neighbors = 0 if Winner == 0

** Calculating number of shared borders between winning subjects at the session level
gen SharedBorder = 0 
replace SharedBorder = 0.5 if neighbors == 1 
replace SharedBorder = 1 if neighbors == 2
bysort session_num Period: egen Agglomeration = total(SharedBorder)
** Agglomeration measures the degree of spatial coordination for a given Period for a Session. 

** Variable measuring total environmental benefits generated from first-best allocations with bids = cost for each submitted bid. 
** Numbers obtained from when experiment calibrated
gen EB_opt = 1344 if Endow1 == 1
replace EB_opt = 1236 if Endow2 == 1
replace EB_opt = 1317 if Endow3 == 1
replace EB_opt = 1426 if Endow1 == 1 & Treatment_new > 6
replace EB_opt = 1298 if Endow2 == 1 & Treatment_new > 6
replace EB_opt = 1469 if Endow3 == 1 & Treatment_new > 6

** Session level expense of supporting the optimal allocation - includes bonus payments (but not joint bonuses since regulator will never pay joint bonus if has cost info)
** Numbers obtained from when experiment calibrated
gen Cost_opt = 3409 if Endow1 == 1
replace Cost_opt = 3443 if Endow2 == 1
replace Cost_opt = 3360 if Endow3 == 1
replace Cost_opt = 3395 if Endow1 == 1 & Treatment_new > 6
replace Cost_opt = 3038 if Endow2 == 1 & Treatment_new > 6
replace Cost_opt = 3225 if Endow3 == 1 & Treatment_new > 6

** Metric measuring cost-effectiveness 
gen POCER_deno = EB_opt/Cost_opt
gen POCER_num  = SessionQuality/SessionPayment
gen POCER = POCER_num/POCER_deno

** Auction Information Markup - This is the value of bid received plus any bonus dependent upon treatment and winning neighbors (if any) less the cost of the project
bysort session_num Period: egen SessionRentNew = total(Profit)

** Total number of winners per period in a session (both individual and joint)
bysort session_num Period: egen TotalWinners = total(Winner)

** Creating variable to record joint bid submissions and account for -1 values where joint bids not submitted
gen Offer_Left_Own99 = Offer_Left_Own
replace Offer_Left_Own99 = 99999 if Offer_Left_Own == -1 & JointTreatmentAug >0
gen Offer_Right_Own99 = Offer_Right_Own
replace Offer_Right_Own99 = 99999 if Offer_Right_Own == -1 & JointTreatmentAug >0

*** Identifying the dominated people when considering all players. These are people who clearly did not understand the auction at all
*** and so would have made negative profits if they were selected even with both neighbors selected. Refer to footnote 17 in paper. 

gen ProfitDomV2 = 0
** For non-joint treatments
replace ProfitDomV2 = Offer-Cost + Edge_Bonus_Left + Edge_Bonus_Right if JointTreatmentAug == 0  
** For joint treatments with bonus multiplier == 2.5
replace ProfitDomV2 = max((Offer-Cost + Edge_Bonus_Left + Edge_Bonus_Right), (Offer_Left_Own - Cost + 2.5*Edge_Bonus_Left + Edge_Bonus_Right), (Offer_Right_Own - Cost + 2.5*Edge_Bonus_Right + Edge_Bonus_Left)) if JointTreatmentAug == 1 & Offer_Left_Own99 != 99999 & Offer_Right_Own99 != 99999
replace ProfitDomV2 = max((Offer-Cost + Edge_Bonus_Left + Edge_Bonus_Right), (Offer_Left_Own - Cost + 2.5*Edge_Bonus_Left + Edge_Bonus_Right)) if JointTreatmentAug == 1 & Offer_Left_Own99 != 99999 & Offer_Right_Own99 == 99999
replace ProfitDomV2 = max((Offer-Cost + Edge_Bonus_Left + Edge_Bonus_Right), (Offer_Right_Own - Cost + 2.5*Edge_Bonus_Right + Edge_Bonus_Left)) if JointTreatmentAug == 1 & Offer_Left_Own99 == 99999 & Offer_Right_Own99 != 99999
** For joint treatments with bonus multiplier == 1.5
replace ProfitDomV2 = max((Offer-Cost + Edge_Bonus_Left + Edge_Bonus_Right), (Offer_Left_Own - Cost + 1.5*Edge_Bonus_Left + Edge_Bonus_Right), (Offer_Right_Own - Cost + 1.5*Edge_Bonus_Right + Edge_Bonus_Left)) if JointTreatmentAug == 2 & Offer_Left_Own99 != 99999 & Offer_Right_Own99 != 99999
replace ProfitDomV2 = max((Offer-Cost + Edge_Bonus_Left + Edge_Bonus_Right), (Offer_Left_Own - Cost + 1.5*Edge_Bonus_Left + Edge_Bonus_Right)) if JointTreatmentAug == 2 & Offer_Left_Own99 != 99999 & Offer_Right_Own99 == 99999
replace ProfitDomV2 = max((Offer-Cost + Edge_Bonus_Left + Edge_Bonus_Right), (Offer_Right_Own - Cost + 1.5*Edge_Bonus_Right + Edge_Bonus_Left)) if JointTreatmentAug == 2 & Offer_Left_Own99 == 99999 & Offer_Right_Own99 != 99999
** For joint treatments with bonus multiplier == 1.5 and individual bonus == 0
replace ProfitDomV2 = max((Offer-Cost), (Offer_Left_Own - Cost + 1.5*Edge_Bonus_Left ), (Offer_Right_Own - Cost + 1.5*Edge_Bonus_Right)) if JointTreatmentAug == 3 & Offer_Left_Own99 != 99999 & Offer_Right_Own99 != 99999
replace ProfitDomV2 = max((Offer-Cost), (Offer_Left_Own - Cost + 1.5*Edge_Bonus_Left)) if JointTreatmentAug == 3 & Offer_Left_Own99 != 99999 & Offer_Right_Own99 == 99999
replace ProfitDomV2 = max((Offer-Cost), (Offer_Right_Own - Cost + 1.5*Edge_Bonus_Right)) if JointTreatmentAug == 3 & Offer_Left_Own99 == 99999 & Offer_Right_Own99 != 99999

gen dominateV2 = 0
replace dominateV2 = 1 if ProfitDomV2 < 0
bysort session_num Period: egen SessionDominateV2 = total(dominateV2)

**********************************************************************************
*** Now we are ready to calculate summary statistics reported in Tables 3a and 3b.
**********************************************************************************

preserve
keep if Subject == 1
drop if SessionDominateV2 >0
collapse (mean) SessionQuality Agglomeration POCER SessionRentNew TotalWinners (semean) seSessionQuality = SessionQuality seAgglomeration = Agglomeration sePOCER = POCER seSessionRentNew = SessionRentNew seTotalWinners = TotalWinners, by(Treatment_new SingleTreatment)
restore

*****************************************************************************************************
*** Now we are ready to compute statistical comparisons reported in Tables 3a, 3b and 4.
*** We correct for multiple hypotheses testing through the Bonferronni Holm calculations done by hand
*****************************************************************************************************

** Repeat code between lines 52 and 214 to generate variables
preserve
keep if Subject == 1
drop if SessionDominateV2 >0
collapse (mean) POCER SessionRentNew SessionQuality Agglomeration TotalWinners, by(Treatment_new session_num)

** Comparing Sigle-Individual & Single-Joint2.5
ranksum SessionRentNew if (Treatment_new==1 | Treatment_new==3), by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint2.5
ranksum SessionRentNew if (Treatment_new==2 | Treatment_new==4), by(Treatment_new) 
** Comparing Sigle-Individual & Single-Joint1.5
ranksum SessionRentNew if (Treatment_new==1 | Treatment_new==5), by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint1.5
ranksum SessionRentNew if (Treatment_new==2 | Treatment_new==6), by(Treatment_new) 
** Comparing Multi-Joint2.5 & Multi-Joint1.5
ranksum SessionRentNew if (Treatment_new==4 | Treatment_new==6), by(Treatment_new) 
** Comparing Single-Joint2.5 & Single-Joint1.5
ranksum SessionRentNew if (Treatment_new==3 | Treatment_new==5), by(Treatment_new) 
** Comparing Single-Joint1.5 & Single-Joint0
ranksum SessionRentNew if (Treatment_new==5 | Treatment_new==7), by(Treatment_new) 
** Comparing Multi-Joint1.5 & Multi-Joint0
ranksum SessionRentNew if (Treatment_new==6 | Treatment_new==8), by(Treatment_new) 

************************************

** Comparing Sigle-Individual & Multi-Individual
ranksum SessionRentNew if (Treatment_new==1 | Treatment_new==2), by(Treatment_new) 
** Comparing Single-Joint2.5 & Multi-Joint2.5
ranksum SessionRentNew if (Treatment_new==3 | Treatment_new==4), by(Treatment_new) 
** Comparing Single-Joint1.5 & Multi-Joint1.5
ranksum SessionRentNew if (Treatment_new==5 | Treatment_new==6), by(Treatment_new) 
** Comparing Single-Joint0 & Multi-Joint0
ranksum SessionRentNew if (Treatment_new==7 | Treatment_new==8), by(Treatment_new) 

************************

** Comparing Single-Individual & Single-Joint2.5
ranksum POCER if (Treatment_new==1 | Treatment_new==3), by(Treatment_new)
** Comparing Multi-Individual & Multi-Joint2.5
ranksum POCER if (Treatment_new==2 | Treatment_new==4), by(Treatment_new) 
** Comparing Sigle-Individual & Single-Joint1.5
ranksum POCER if (Treatment_new==1 | Treatment_new==5), by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint1.5
ranksum POCER if (Treatment_new==2 | Treatment_new==6), by(Treatment_new) 
** Comparing Multi-Joint2.5 & Multi-Joint1.5
ranksum POCER if (Treatment_new==4 | Treatment_new==6), by(Treatment_new) 
** Comparing Single-Joint2.5 & Single-Joint1.5
ranksum POCER if (Treatment_new==3 | Treatment_new==5) , by(Treatment_new) 
** Comparing Single-Joint1.5 & Single-Joint0
ranksum POCER if (Treatment_new==5 | Treatment_new==7), by(Treatment_new) 
** Comparing Multi-Joint1.5 & Multi-Joint0
ranksum POCER if (Treatment_new==6 | Treatment_new==8), by(Treatment_new)

**********************************

** Comparing Single-Individual & Multi-Individual
ranksum POCER if (Treatment_new==1 | Treatment_new==2), by(Treatment_new) 
** Comparing Single-Joint2.5 & Multi-Joint2.5
ranksum POCER if (Treatment_new==3 | Treatment_new==4), by(Treatment_new) 
** Comparing Single-Joint1.5 & Multi-Joint1.5
ranksum POCER if (Treatment_new==6 | Treatment_new==5), by(Treatment_new) 
** Comparing Single-Joint0 & Multi-Joint0
ranksum POCER if (Treatment_new==7 | Treatment_new==8), by(Treatment_new)  

****************************************************

** Comparing Sigle-Individual & Single-Joint2.5
ranksum SessionQuality if (Treatment_new==1 | Treatment_new==3) , by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint2.5
ranksum SessionQuality if (Treatment_new==2 | Treatment_new==4), by(Treatment_new) 
** Comparing Sigle-Individual & Single-Joint1.5
ranksum SessionQuality if (Treatment_new==1 | Treatment_new==5), by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint1.5
ranksum SessionQuality if (Treatment_new==2 | Treatment_new==6), by(Treatment_new) 
** Comparing Multi-Joint2.5 & Multi-Joint1.5
ranksum SessionQuality if (Treatment_new==4 | Treatment_new==6) , by(Treatment_new) 
** Comparing Single-Joint2.5 & Single-Joint1.5
ranksum SessionQuality if (Treatment_new==3 | Treatment_new==5) , by(Treatment_new) 
** Comparing Single-Joint1.5 & Single-Joint0
ranksum SessionQuality if (Treatment_new==5 | Treatment_new==7) , by(Treatment_new) 
** Comparing Multi-Joint1.5 & Multi-Joint0
ranksum SessionQuality  if (Treatment_new==6 | Treatment_new==8), by(Treatment_new) 

**************************************

** Comparing Single-Individual & Multi-Individual
ranksum SessionQuality if (Treatment_new==1 | Treatment_new==2), by(Treatment_new) 
** Comparing Single-Joint2.5 & Multi-Joint2.5
ranksum SessionQuality if (Treatment_new==3 | Treatment_new==4), by(Treatment_new) 
** Comparing Single-Joint1.5 & Multi-Joint1.5
ranksum SessionQuality if (Treatment_new==6 | Treatment_new==5), by(Treatment_new) 
** Comparing Single-Joint0 & Multi-Joint0
ranksum SessionQuality if (Treatment_new==7 | Treatment_new==8), by(Treatment_new) 

***************************************************

** Comparing Single-Individual & Single-Joint2.5
ranksum Agglomeration if (Treatment_new==1 | Treatment_new==3) , by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint2.5
ranksum Agglomeration if (Treatment_new==2 | Treatment_new==4), by(Treatment_new) 
** Comparing Sigle-Individual & Single-Joint1.5
ranksum Agglomeration if (Treatment_new==1 | Treatment_new==5), by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint1.5
ranksum Agglomeration if (Treatment_new==2 | Treatment_new==6), by(Treatment_new) 
** Comparing Multi-Joint2.5 & Multi-Joint1.5
ranksum Agglomeration if (Treatment_new==4 | Treatment_new==6) , by(Treatment_new) 
** Comparing Single-Joint2.5 & Single-Joint1.5
ranksum Agglomeration if (Treatment_new==3 | Treatment_new==5) , by(Treatment_new) 
** Comparing Single-Joint1.5 & Single-Joint0
ranksum Agglomeration if (Treatment_new==5 | Treatment_new==7) , by(Treatment_new) 
** Comparing Multi-Joint1.5 & Multi-Joint0
ranksum Agglomeration  if (Treatment_new==6 | Treatment_new==8), by(Treatment_new) 

********************************************************

** Comparing Single-Individual & Multi-Individual
ranksum Agglomeration if (Treatment_new==1 | Treatment_new==2), by(Treatment_new) 
** Comparing Single-Joint2.5 & Multi-Joint2.5
ranksum Agglomeration if (Treatment_new==3 | Treatment_new==4), by(Treatment_new) 
** Comparing Single-Joint1.5 & Multi-Joint1.5
ranksum Agglomeration if (Treatment_new==6 | Treatment_new==5), by(Treatment_new) 
** Comparing Single-Joint0 & Multi-Joint0
ranksum Agglomeration if (Treatment_new==7 | Treatment_new==8), by(Treatment_new) 

**********************************************************************************************

** Comparing Single-Individual & Single-Joint2.5
ranksum TotalWinners if (Treatment_new==1 | Treatment_new==3) , by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint2.5
ranksum TotalWinners if (Treatment_new==2 | Treatment_new==4), by(Treatment_new) 
** Comparing Sigle-Individual & Single-Joint1.5
ranksum TotalWinners if (Treatment_new==1 | Treatment_new==5), by(Treatment_new) 
** Comparing Multi-Individual & Multi-Joint1.5
ranksum TotalWinners if (Treatment_new==2 | Treatment_new==6), by(Treatment_new) 
** Comparing Multi-Joint2.5 & Multi-Joint1.5
ranksum TotalWinners if (Treatment_new==4 | Treatment_new==6) , by(Treatment_new) 
** Comparing Single-Joint2.5 & Single-Joint1.5
ranksum TotalWinners if (Treatment_new==3 | Treatment_new==5) , by(Treatment_new) 
** Comparing Single-Joint1.5 & Single-Joint0
ranksum TotalWinners if (Treatment_new==5 | Treatment_new==7) , by(Treatment_new) 
** Comparing Multi-Joint1.5 & Multi-Joint0
ranksum TotalWinners  if (Treatment_new==6 | Treatment_new==8), by(Treatment_new) 

********************************************************

** Comparing Single-Individual & Multi-Individual
ranksum TotalWinners if (Treatment_new==1 | Treatment_new==2), by(Treatment_new) 
** Comparing Single-Joint2.5 & Multi-Joint2.5
ranksum TotalWinners if (Treatment_new==3 | Treatment_new==4), by(Treatment_new) 
** Comparing Single-Joint1.5 & Multi-Joint1.5
ranksum TotalWinners if (Treatment_new==6 | Treatment_new==5), by(Treatment_new) 
** Comparing Single-Joint0 & Multi-Joint0
ranksum TotalWinners if (Treatment_new==7 | Treatment_new==8), by(Treatment_new) 

**********************************************************************************************

restore

** ** Repeat code between lines 52 and 214 to generate variables and then compute tests for Periods 5-9 for data presented in Appendix Table B1a and B1b


*************************************************
*** Regression Analysis presented in Table 5  ***
*************************************************

** Model 1 
cgmreg Offer Cost costsq Quality SingleTreatment Endow1 Endow2 RiskAverse i.param_order Period if JointTreatmentAug == 0 & dominateV2 == 0, cluster(session_num)
** Model 1 for Table B2 in Appendix
cgmreg Offer Cost costsq Quality SingleTreatment Endow1 Endow2 RiskAverse i.param_order Period if JointTreatmentAug == 0 & dominateV2 == 0 & Period > 4, cluster(session_num)

** Model 2
cgmreg Offer Cost costsq Quality SuperBonus SingleTreatment JointSingleInt3 Endow1 Endow2 RiskAverse i.param_order Period if dominateV2 == 0 & (JointTreatmentAug == 1| JointTreatmentAug == 2), cluster(session_num)
** Model 2 for Table B2 in Appendix
cgmreg Offer Cost costsq Quality SuperBonus SingleTreatment JointSingleInt3 Endow1 Endow2 RiskAverse i.param_order Period if dominateV2 == 0 & (JointTreatmentAug == 1| JointTreatmentAug == 2) & Period > 4, cluster(session_num)

** Model 3
cgmreg Offer Cost costsq Quality NoIndivBonus SingleTreatment JointSingleInt4 Endow1 Endow2 RiskAverse i.param_order Period if JointTreatmentAug >1 & dominateV2 == 0 , cluster(session_num)
** Model 3 for Table B2 in Appendix
cgmreg Offer Cost costsq Quality NoIndivBonus SingleTreatment JointSingleInt4 Endow1 Endow2 RiskAverse i.param_order Period if JointTreatmentAug >1 & dominateV2 == 0 & Period > 4 , cluster(session_num)

*** Now we need to do some data manipulation to get the data in long format from wide format 
*** so that we can run regressions for the joint bids. This is because for each subject
*** there can me 1 or 2 joint bids.
*** In order to do this, we shall take work with the master data and confirmed joint bids file (confirmed bids are used for winner determination) 

************************************************************************************
*** Now we need to manipulate the subject.dta file to do regressions with joint bids 
************************************************************************************

preserve
keep Quality dominateV2 Edge_Benefit_Left Edge_Benefit_Right Period session session_num subjID Treatment_new Interactions JointSingleInt1 JointSingleInt2 JointSingleInt3 JointSingleInt4

*** Now we shall generate variables which will be used for creating the reshaped Long data set and then used in the regression
gen QualityL1 = Quality
gen QualityL2 = Quality
gen dominateV2L1 = dominateV2
gen dominateV2L2 = dominateV2
gen BonusL1 = Edge_Benefit_Left
gen BonusL2 = Edge_Benefit_Right
gen counterReshape1 = 1
gen counterReshape2 = 2
gen subjID_long = subjID*10+Period

** Now we reshape the data 
reshape long QualityL dominateV2L BonusL counterReshape, i(subjID_long) j(bidnmbr)

** ID variable which will be used to merge subjects and confirmed data files
gen subjID_merge = subjID_long*10+bidnmbr

** Merge the above information with Confirmed_Bids.dta file
merge 1:m subjID_merge using "confirmed.dta" 

*** Now we need to create variables necessary for the analysis in the new merged file
gen Endow1 = 0
replace Endow1 = 1 if param_order == 1 & (Period == 1| Period == 4| Period == 7) 
replace Endow1 = 1 if param_order == 2 & (Period == 3| Period == 6| Period == 9)
replace Endow1 = 1 if param_order == 3 & (Period == 3| Period == 6| Period == 9)
gen Endow2 = 0
replace Endow2 = 1 if param_order == 1 & (Period == 2| Period == 5| Period == 8)
replace Endow2 = 1 if param_order == 2 & (Period == 1| Period == 4| Period == 7)
replace Endow2 = 1 if param_order == 3 & (Period == 2| Period == 5| Period == 8)
gen Endow3 = 0
replace Endow3 = 1 if param_order == 1 & (Period == 3| Period == 6| Period == 9)
replace Endow3 = 1 if param_order == 2 & (Period == 2| Period == 5| Period == 8)
replace Endow3 = 1 if param_order == 3 & (Period == 1| Period == 4| Period == 7)

** Generating variable for subject that records joint bid(s) confirmed and used for winner determination
gen OfferJoint = Offer_Subject_Right if joint == 1 & Subject == joint_Subject_Right
replace OfferJoint = Offer_Subject_Left if joint == 1 & Subject == joint_Subject_Left

** Generating variable for subject that records cost values. We do it this way since the Cost variable for joint bids records total cost of both joint bidders together
gen CostJoint = Cost_Subject_Right if joint == 1 & Subject == joint_Subject_Right
replace CostJoint = Cost_Subject_Left if joint == 1 & Subject == joint_Subject_Left
gen CostJointsq = CostJoint*CostJoint

gen SingleTreatment = 1 if Treatment_new == 1 | Treatment_new == 3 | Treatment_new == 5 | Treatment_new == 7
replace SingleTreatment = 0 if SingleTreatment != 1

** Dummy variable for Joint Bidding treatment
gen JointTreatment = 1 if Treatment_new == 3 | Treatment_new == 4 | Treatment_new == 5 |Treatment_new == 6 | Treatment_new == 7 | Treatment_new == 8
replace JointTreatment = 0 if JointTreatment != 1

** Dummy variable for No Individual Bonus treatment
gen NoIndivBonus = 1 if Treatment_new>6
replace NoIndivBonus = 0 if Treatment_new<7

** Dummy variable for Joint Individual Bonus = 1.5 treatment
gen SuperBonus = 0 if Treatment_new == 3| Treatment_new == 4
replace SuperBonus = 1 if Treatment_new >= 5

** Dummy variable for Joint bidding treatments pooling data for Single and Multi round treatments
gen JointTreatmentAug = 0 if JointTreatment == 0
replace JointTreatmentAug = 1 if Treatment_new == 3| Treatment_new == 4
replace JointTreatmentAug = 2 if Treatment_new == 5| Treatment_new == 6
replace JointTreatmentAug = 3 if Treatment_new == 7| Treatment_new == 8

** Model 4
cgmreg OfferJoint CostJoint CostJointsq QualityL BonusL SuperBonus SingleTreatment JointSingleInt3 Endow1 Endow2 RiskAverse i.param_order Period if (JointTreatmentAug == 1|JointTreatmentAug == 2) & dominateV2 == 0 & joint == 1 , cluster(session_num)
** Model 4 for Table B2 in Appendix
cgmreg OfferJoint CostJoint CostJointsq QualityL BonusL SuperBonus SingleTreatment JointSingleInt3 Endow1 Endow2 RiskAverse i.param_order Period if (JointTreatmentAug == 1|JointTreatmentAug == 2) & dominateV2 == 0 & joint == 1 & Period > 4 , cluster(session_num)

** Model 5  
cgmreg OfferJoint CostJoint CostJointsq QualityL BonusL NoIndivBonus SingleTreatment JointSingleInt4 Endow1 Endow2 RiskAverse i.param_order Period if JointTreatmentAug >1 & dominateV2 == 0 & joint == 1 , cluster(session_num)
** Model 5 for Table B2 in Appendix
cgmreg OfferJoint CostJoint CostJointsq QualityL BonusL NoIndivBonus SingleTreatment JointSingleInt4 Endow1 Endow2 RiskAverse i.param_order Period if JointTreatmentAug >1 & dominateV2 == 0 & joint == 1 & Period > 4 , cluster(session_num)

restore

*********************************************************
*** Analysis of 3 Joint Bidding Steps presented in Table 6
*********************************************************

*** The Analysis below is for Row 1. 

use "subjects.dta", clear

** Variable recording total number of joint bid expressions of interest by subjects
gen Joint_Expressions = Joint_Left + Joint_Right
bysort session_num Period: egen Joint_Expressions_Sessions = total(Joint_Expressions)
preserve
keep if Treatment_new>2
** Eliminating dominated observations
drop if Period == 1 & session_num == 3
drop if Period == 6 & session_num == 5
drop if Period == 5 & session_num == 6
drop if Period == 6 & session_num ==6
drop if Period == 1 & session_num == 13
drop if Period == 1 & session_num == 17
drop if Period == 1 & session_num == 36
drop if Period == 7 & session_num == 39
drop if Period == 4 & session_num ==47
keep if Subject == 1
** Computing summary statistics 
collapse (mean) Joint_Expressions_Sessions (semean) seJoint_Expressions_Sessions = Joint_Expressions_Sessions, by(Treatment_new)
restore

*** Preparing data set for statistical comparisons
bysort session_num Period: egen Joint_Expressions_Sessions = total(Joint_Expressions)
preserve
keep if Treatment_new>2
** Eliminating dominated observations
drop if Period == 1 & session_num == 3
drop if Period == 6 & session_num == 5
drop if Period == 5 & session_num == 6
drop if Period == 6 & session_num ==6
drop if Period == 1 & session_num == 13
drop if Period == 1 & session_num == 17
drop if Period == 1 & session_num == 36
drop if Period == 7 & session_num == 39
drop if Period == 4 & session_num ==47
keep if Subject == 1
collapse (mean) Joint_Expressions_Sessions, by(Treatment_new session_num)

** Comparing Multi-Joint2.5 & Multi-Joint1.5
ranksum Joint_Expressions_Sessions if (Treatment_new==4 | Treatment_new==6) , by(Treatment_new) 

** Comparing Single-Joint2.5 & Single-Joint1.5
ranksum Joint_Expressions_Sessions if (Treatment_new==3 | Treatment_new==5) , by(Treatment_new) 

** Comparing Single-Joint1.5 & Single-Joint0
ranksum Joint_Expressions_Sessions if (Treatment_new==5 | Treatment_new==7) , by(Treatment_new) 

** Comparing Multi-Joint1.5 & Multi-Joint0
ranksum Joint_Expressions_Sessions  if (Treatment_new==6 | Treatment_new==8), by(Treatment_new) 
restore

*** The Analysis below is for Row 2. This considers the number of joint bid pairs submitted by submitter subjects for consideration by confirming neighbors in Round 1

use "contracts.dta", clear

*** Summary statistics
preserve
** Only working with Round 1 data
keep if Round == 1
** Only working with Joint bid treatment data
keep if Treatment_new>2
** Eliminating observations of periods with players with dominated observations (refer to code in lines 210 - 228)
drop if Period == 1 & session_num == 3
drop if Period == 6 & session_num == 5
drop if Period == 5 & session_num == 6
drop if Period == 6 & session_num ==6
drop if Period == 1 & session_num == 13
drop if Period == 1 & session_num == 17
drop if Period == 1 & session_num == 36
drop if Period == 7 & session_num == 39
drop if Period == 4 & session_num ==47

** Variable recording number of instances of pairs of joint bids
bysort session_num Period: egen BothVote = total(joint)
** Create a variable to filter values for data analysis
sort session_num Period subjID
bysort session_num Period: gen count_obs = _n

** Calculating summary statistics
collapse (mean) BothVote (semean) seBothVote = BothVote if count_obs == 1, by(Treatment_new)
restore

*** Statistical comparisons
preserve
keep if Round == 1
keep if Treatment_new>2
drop if Period == 1 & session_num == 3
drop if Period == 6 & session_num == 5
drop if Period == 5 & session_num == 6
drop if Period == 6 & session_num ==6
drop if Period == 1 & session_num == 13
drop if Period == 1 & session_num == 17
drop if Period == 1 & session_num == 36
drop if Period == 7 & session_num == 39
drop if Period == 4 & session_num ==47

bysort session_num Period: egen BothVote = total(joint)
bysort session_num Period: gen count_obs = _n

** Conducting non-parametric tests
collapse (mean) BothVote if count_obs == 1, by(Treatment_new session_num)

** Comparing Multi-Joint2.5 & Multi-Joint1.5
ranksum BothVote if (Treatment_new==4 | Treatment_new==6) , by(Treatment_new) 

** Comparing Single-Joint2.5 & Single-Joint1.5
ranksum BothVote if (Treatment_new==3 | Treatment_new==5) , by(Treatment_new) 

** Comparing Single-Joint1.5 & Single-Joint0
ranksum BothVote if (Treatment_new==5 | Treatment_new==7) , by(Treatment_new) 

** Comparing Multi-Joint1.5 & Multi-Joint0
ranksum BothVote  if (Treatment_new==6 | Treatment_new==8), by(Treatment_new) 
restore

*** The Analysis below is for Row 3. This considers the number of joint bid pairs confirmed in the final round of a period and used for winner determination

use "confirmed.dta", clear

preserve
bysort session_num Period: egen maxRound = max(Round)
keep if Round == maxRound
** Only working with Joint bid treatment data
keep if Treatment_new>2
** Eliminating observations of periods with players with dominated observations (refer to code in lines 210 - 228)
drop if Period == 1 & session_num == 3
drop if Period == 6 & session_num == 5
drop if Period == 5 & session_num == 6
drop if Period == 6 & session_num ==6
drop if Period == 1 & session_num == 13
drop if Period == 1 & session_num == 17
drop if Period == 1 & session_num == 36
drop if Period == 7 & session_num == 39
drop if Period == 4 & session_num ==47

** Variable recording number of instances of pairs of joint bids
bysort session_num Period: egen BothVote = total(joint)
** Create a variable to filter values for data analysis
sort session_num Period subjID
bysort session_num Period: gen count_obs = _n

** Calculating summary statistics
collapse (mean) BothVote (semean) seBothVote = BothVote if count_obs == 1, by(Treatment_new)

restore

*** Statistical comparisons
preserve
bysort session_num Period: egen maxRound = max(Round)
keep if Round == maxRound
** Only working with Joint bid treatment data
keep if Treatment_new>2
** Eliminating observations of periods with players with dominated observations (refer to code in lines 210 - 228)
drop if Period == 1 & session_num == 3
drop if Period == 6 & session_num == 5
drop if Period == 5 & session_num == 6
drop if Period == 6 & session_num ==6
drop if Period == 1 & session_num == 13
drop if Period == 1 & session_num == 17
drop if Period == 1 & session_num == 36
drop if Period == 7 & session_num == 39
drop if Period == 4 & session_num ==47

** Variable recording number of instances of pairs of joint bids
bysort session_num Period: egen BothVote = total(joint)
** Create a variable to filter values for data analysis
sort session_num Period subjID
bysort session_num Period: gen count_obs = _n

** Calculating summary statistics
collapse (mean) BothVote (semean) seBothVote = BothVote if count_obs == 1, by(Treatment_new)
bysort session_num Period: egen BothVote = total(joint)
sort session_num Period subjID
bysort session_num Period: gen count_obs = _n
collapse (mean) BothVote if count_obs == 1, by(Treatment_new session_num)
** Comparing Multi-Joint2.5 & Multi-Joint1.5
ranksum BothVote if (Treatment_new==4 | Treatment_new==6) , by(Treatment_new) 

** Comparing Single-Joint2.5 & Single-Joint1.5
ranksum BothVote if (Treatment_new==3 | Treatment_new==5) , by(Treatment_new) 

** Comparing Single-Joint1.5 & Single-Joint0
ranksum BothVote if (Treatment_new==5 | Treatment_new==7) , by(Treatment_new) 

** Comparing Multi-Joint1.5 & Multi-Joint0
ranksum BothVote  if (Treatment_new==6 | Treatment_new==8), by(Treatment_new) 
restore


**********************************************************************************
*** Analysis of comparison of markup of joint and single bids presented in Table 7
**********************************************************************************

use "subjects.dta", clear

preserve
** Generating ID variable for reshaping data from wide to long for subjects file
gen testID = subjID*10+Period
gen counterReshape1 = 1
gen counterReshape2 = 2
gen counterReshape3 = 3
gen counterReshape4 = 4

** Rename Offer and Cost variable since confirmed.data file also has variables with this name but for confirmed joint bids
rename Offer OfferI
rename Cost CostI

** Generate variable for individual offer markups
gen IndividualOfferMarkup = (OfferI-CostI)/CostI


reshape long counterReshape, i(testID) j(bidnmbr)
** Now we have individual bid data for each subject (twice) and right and left neighbor in the OfferI variable in one column for each period
** This is a new ID which will be used when merging this file with the another file containing data on joint bids. 
gen mergeID1 = testID*10+bidnmbr 

save "subjects_long.dta", replace 

*** Already created and saved

restore

** Now we use confirmed.dta file 

use "confirmed.dta", clear

preserve

** Variable recording whether joint bid with right neighbor confirmed
gen jointR = 1 if joint == 1 & Subject == joint_Subject_Left
** Variable recording whether joint bid with left neighbor confirmed
gen jointL = 1 if joint == 1 & Subject == joint_Subject_Right

** already defined

** Generating a counter variable which takes a value of 1 recording a joint bid with right neighbor and 2 with left neighbor. 
** If only one joint bid submitted then for subject only one value is available and other is missing
gen NhbrCntr = 1 if joint == 1 & jointL == 1
replace NhbrCntr = 2 if joint == 1 & jointR == 1

** already defined

** Markup of player submitter in their left window
gen MarkupSubL = (Offer_Subject_Right - Cost_Subject_Right)/Cost_Subject_Right if Subject == joint_Subject_Right & joint == 1 & Round == FinalRound
** Markup of player submitter in their right window
gen MarkupSubR = (Offer_Subject_Left - Cost_Subject_Left)/Cost_Subject_Left if Subject == joint_Subject_Left & joint == 1 & Round == FinalRound
** Markup of left neighbor who confirms in left window
gen MarkConNL = (Offer_Subject_Left - Cost_Subject_Left)/Cost_Subject_Left if Subject == joint_Subject_Right & joint == 1 & Round == FinalRound
** Markup of right neighbor who confirms in righ window  
gen MarkConNR = (Offer_Subject_Right - Cost_Subject_Right)/Cost_Subject_Right if Subject == joint_Subject_Left & joint == 1 & Round == FinalRound

** MarkupSubL and MarkConNL are together in left pair
** MarkupSubR and MarkConNR are together in right pair

** Generating variable that tracks whether subject submitted bids in both left and right windows  
sort session_num  subjID Period NhbrCntr
drop if joint==0
bysort subjID Period: gen counter = _N
** Generating variable moving bids corresponding to those submitted with right neighbor to the same row as bids corresponding to those with left neighbor
** This is for subject-pairs who submitted bids with both left and right neighbors as indicated by counter == 2
bysort subjID Period: gen MoveSubR = MarkupSubR[_n+1] if NhbrCntr == 1 & counter == 2
bysort subjID Period: gen MoveConR = MarkConNR[_n+1] if NhbrCntr == 1 & counter == 2

*** The above two steps moves data for bids with right neighbor to same row as bids with left neighbor for those who submitted two joint bids
*** This variable does not include data for subjects who submitted bids with right neighbor only.
*** So we do the next two steps so that the MoveSubR and MoveConR variables contain the data for these people too
*** There can be no missing values for MoveSubR and MoveConR as long as a bid was submitted in the right window
replace MoveSubR = MarkupSubR if NhbrCntr==2 & counter == 1
replace MoveConR = MarkConNR if NhbrCntr==2 & counter == 1

** Preparing dataset to reshape to long format
gen JointOfferMarkup1 = MarkupSubL
gen JointOfferMarkup2 = MoveConR
gen JointOfferMarkup3 = MoveSubR
gen JointOfferMarkup4 = MarkConNL

gen counterReshape1 = 1
gen counterReshape2 = 2
gen counterReshape3 = 3
gen counterReshape4 = 4

*** MarkupSubL and MarkConNL are together for bid submitted with left neighbor
*** MarkupSubR and MarkConNR are together for bid submitted with left neighbor

gen testID = subjID*10+Period
gen filter = 1 if (JointOfferMarkup1!=.|JointOfferMarkup2!=.|JointOfferMarkup3!=.|JointOfferMarkup4!=.)

drop if filter ==.
reshape long JointOfferMarkup counterReshape, i(testID) j(bidnmbr)
gen mergeID1 = testID*10+bidnmbr 

** Merge with subjects_long.dta file
merge m:1 mergeID1 using "subjects_long.dta"

** Eliminating the dominated observations
drop if Period == 1 & session_num == 3
drop if Period == 6 & session_num == 5
drop if Period == 5 & session_num == 6
drop if Period == 6 & session_num ==6
drop if Period == 1 & session_num == 13
drop if Period == 1 & session_num == 17
drop if Period == 1 & session_num == 36
drop if Period == 7 & session_num == 39
drop if Period == 4 & session_num ==47

** Eliminating observations of those subjects whose bids were not used for winner determination as not confirmed
drop if JointOfferMarkup == .
** Summary statistics
collapse  (mean) JointOfferMarkup IndividualOfferMarkup (semean) seJointOfferMarkup = JointOfferMarkup seIndividualOfferMarkup = IndividualOfferMarkup, by (Treatment_new)

** Statistical comparisons presented in Table 7
collapse  (mean) JointOfferMarkup IndividualOfferMarkup, by (Treatment_new session_num)
by Treatment_new, sort: signrank IndividualOfferMarkup = JointOfferMarkup 

*** For summary statistics repeat the process with collapse with calculations pooled by session_num for each treatment

restore

